package jaas;

import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;

import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;

public class LoginContextTest {
	public static void main(String[] args) throws LoginException, PrivilegedActionException {
		// 一段典型的代码如下
		LoginContext lc = new LoginContext("MyExample");
		try {
			lc.login();
		} catch (LoginException e) {
			// Authentication failed.
		}

		// Authentication successful, we can now continue.
		// We can use the returned Subject if we like.
		Subject sub = lc.getSubject();
		Subject.doAs(sub, new PrivilegedExceptionAction() {

			@Override
			public Object run() throws Exception {
				// TODO Auto-generated method stub
				return null;
			}
		});
	}

}
